package com.jn.news.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/**
 * 数据库工具类
 */
public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "News.db";  // 数据库名称
    private static final int DATABASE_VERSION = 1;                // 数据库版本

    public DatabaseHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建用户表
        String sql = "create table user(id integer primary key autoincrement,name varchar(64),password varchar(64),phone varchar(64),email varchar(11),qq varchar(20))";
        String collectionSql = "create table collection(id integer primary key autoincrement," +
                "news_id varchar(64)," +
                "user_id integer,"+
                "title varchar(64)," +
                "ctime varchar(64)," +
                "source varchar(64)," +
                "picurl varchar(200)," +
                "url varchar(200))";
        //execSQL用于执行SQL语句 完成数据库的创建
        db.execSQL(sql);
        db.execSQL(collectionSql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
